package com.stoken.web.control;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.stoken.dao.AchievementListDao;
import com.stoken.domain.AchievementList;
import com.stoken.domain.MemberBaseInfo;
import com.stoken.domain.MemberShopWallet;
import com.stoken.domain.MemberWallet;
import com.stoken.domain.TypeLineInfo;
import com.stoken.service.AchievementListService;
import com.stoken.service.MemberShopWalletService;
import com.stoken.service.MemberWalletService;
import com.stoken.web.StokenUtils;
import com.symbio.commons.Compositor;
import com.symbio.commons.Page;
import com.symbio.commons.Compositor.CompositorType;
import com.symbio.utils.WebUtils;

/**
 * 财务管理-代币钱包管理web控制层
 * @author Fred
 *
 */

@Controller
@RequestMapping("/financial")
public class MemberStokenWalletControl {
	
	@Autowired
	private AchievementListService achievementListService;
	
	@Autowired
	private MemberWalletService memberWalletService;
	
	@Autowired
	private MemberShopWalletService memberShopWalletService;
	
	
	/**
	 * 业绩查询
	 * @param request
	 * @param modeMape
	 * @return
	 */
	@RequestMapping("/achievementList")
	public String performaanceList(HttpServletRequest request,ModelMap modeMape)
	{		
		return "/financial/performance";
	}
	
	/**
	 * 业绩查询数据
	 * @param request
	 * @param modeMape
	 * @return
	 */
	@RequestMapping("/achievementData")
	public String loadPerformaanceData(HttpServletRequest request,ModelMap modeMape,String startDate,String endDate){
		
		Page<AchievementList> pageData = new Page<AchievementList>();
		//给pageData设置参数
		WebUtils.setPageDataParameter(request, pageData);
		Compositor compositor = new Compositor("id",CompositorType.DESC);
		pageData.setCompositor(compositor);
	
		//得到当前登录的用户名
		//获得session里面的user信息
		MemberBaseInfo  mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		
		pageData = achievementListService.find(pageData,mbi.getBaseUsername());		
	    modeMape.addAttribute("pageData", pageData);
	    
	    Pagination page = new Pagination();
		page.setIntTotalNum((int)pageData.getPagination().getTotalCount());
		page.setCurpage(pageData.getPagination().getPageNo());
		page.setPagenum(pageData.getPagination().getPageSize());
		modeMape.addAttribute("pagination", page.showPages());
		 return "/financial/performanceData";	
	}
	
	/**
	 * 提现
	 * @param request
	 * @param modeMape
	 * @return
	 */
	@RequestMapping("/withdrawalsList")
	public String withdrawalsList(HttpServletRequest request,ModelMap modeMape)
	{	
		//获得session里面的user信息
	    MemberBaseInfo  mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
	    MemberWallet memberWallet = memberWalletService.findWalletByUsername(mbi.getBaseUsername());
	    modeMape.addAttribute("memberWallet", memberWallet);
		return "/financial/applycash";
	}
	
	/**
	 * 转账管理
	 * @param request
	 * @param modeMape
	 * @return
	 */
	@RequestMapping("/transfer")
	public String transfer(HttpServletRequest request,ModelMap modeMape)
	{		
		//获得session里面的user信息
	    MemberBaseInfo  mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
	    MemberWallet memberWallet = memberWalletService.findWalletByUsername(mbi.getBaseUsername());
	    MemberShopWallet memberShopWallet = memberShopWalletService.getShopWalletByBaseUserName(mbi.getBaseUsername());
	    
	    modeMape.addAttribute("memberWallet", memberWallet);
	    modeMape.addAttribute("memberShopWallet", memberShopWallet);
		return "/financial/transfer";
	}
}
